﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Housing;
using Microsoft.ApplicationBlocks.Data;

public partial class ManageCenter_Index : System.Web.UI.Page
{
    SubsidyRecord subsidy = new SubsidyRecord();
    ReduceRecord reduce = new ReduceRecord();
    KindRecord kind = new KindRecord();
    Apply apply = new Apply();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserStreet"] == null)
            WebHelper.AlertAndRedirect("登陆超时，请重新登陆", "../Login.aspx");
        PageBind();
        if (!IsPostBack)
        {
            //Apply apply = new Apply();
            //DataSet ds = apply.GetApplyListOrderByUserTypeAndStreet(Session["UserType"].ToString(), "%");
            //gvfinallyushow.DataSource = ds;
            //gvfinallyushow.DataBind();
        }
        
    }

    //protected void ddlstreet_SelectedIndexChanged2(object sender, EventArgs e)
    //{
    //    Apply apply = new Apply();
    //    DataSet ds = apply.GetApplyListOrderByUserTypeAndStreet(Session["UserType"].ToString(), ddlstreet.SelectedValue);
    //    gvfinallyushow.DataSource = ds;
    //    gvfinallyushow.DataBind();
    //}
    protected void PageBind()
    {
        //int year = Convert.ToInt32(DateTime.Now.Year.ToString());
        //for (int i = year; i < year + 1; i++)
        //{
        //    startYear.Items.Add(i.ToString());
        //}
        //startMonth.Items.Clear();
        //for (int i = 6; i < 13; i++)
        //{
        //    startMonth.Items.Add(i.ToString());

        //}


        //GridView_applyHistory.DataSource = ApplyHistory.GetApplyHistoryListOrderByUserTypeAndStreet(ddlstreet.SelectedValue);
        //GridView_applyHistory.DataBind();

        //GridView_applyHistory_check.DataSource = ApplyHistory.GetApplyHistory_checked(ddlstreet.SelectedValue);
        //GridView_applyHistory_check.DataBind();
        


        ////显示当月租金减免调整项(供审核)
        //DataSet dsredchanges = reduce.GetReduceChanges(ddlstreet.SelectedValue);
        //gvshowredchanges.DataSource = dsredchanges;
        //gvshowredchanges.DataBind();
        ////显示当月实物配租调整项(供审核)
        //DataSet dskindchanges = kind.GetKindChanges(ddlstreet.SelectedValue);
        //gvshowkindchanges.DataSource = dskindchanges;
        //gvshowkindchanges.DataBind();
        ////显示当月租金补贴调整项(供审核)

        ////显示当月租金补贴续办明细(供审核)
        //DataSet dssubcontinue = subsidy.GetSubsidyContinues(ddlstreet.SelectedValue);
        //gbshowsubsidycontinue.DataSource = dssubcontinue;
        //gbshowsubsidycontinue.DataBind();
        ////显示当月租金减免续办明细(供审核)
        //DataSet dsredcontinue = reduce.GetReduceContinues(ddlstreet.SelectedValue);
        //gbshowreducecontinue.DataSource = dsredcontinue;
        //gbshowreducecontinue.DataBind();
        ////显示当月实物配租续办明细(供审核)
        //DataSet dskindcontinue = kind.GetKindContinues(ddlstreet.SelectedValue);
        //gbshowkindcontinue.DataSource = dskindcontinue;
        //gbshowkindcontinue.DataBind();
        ////显示当月续办明细(供审核)
        //DataSet dsreissue = apply.GetReissue(ddlstreet.SelectedValue);
        //gvreissue.DataSource = dsreissue;
        //gvreissue.DataBind();
    }
    protected void ddlstreet_SelectedIndexChanged(object sender, EventArgs e)
    {
        PageBind();
    }
    protected void gbshowkindcontinue_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        LinkButton lkbpass = (LinkButton)e.Row.FindControl("lkbtnkindpass");
        if (lkbpass != null)
            lkbpass.Attributes.Add("onclick", "return confirm('确定通过审核吗？')");
        LinkButton lkbunpass = (LinkButton)e.Row.FindControl("lkbtnkindpass");
        if (lkbunpass != null)
            lkbunpass.Attributes.Add("onclick", "return confirm('确定否决审核吗？')");
    }
    protected void gbshowkindcontinue_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
        Label longid = (Label)row.FindControl("lbllongid");
        if (longid != null)
        {
            if (e.CommandName == "pass")
            {
                kind.SetKindContinuePass(longid.Text,Convert.ToInt32(e.CommandArgument.ToString()));
                PageBind();
            }
            if (e.CommandName == "unpass")
            {
                kind.SetKindContinueUnPass(Convert.ToInt32(e.CommandArgument.ToString()));
                PageBind();
            }
        }
    }
    protected void gbshowreducecontinue_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        LinkButton lkbpass = (LinkButton)e.Row.FindControl("lkbtnredpass");
        if (lkbpass != null)
            lkbpass.Attributes.Add("onclick", "return confirm('确定通过审核吗？')");
        LinkButton lkbunpass = (LinkButton)e.Row.FindControl("lkbtnredpass");
        if (lkbunpass != null)
            lkbunpass.Attributes.Add("onclick", "return confirm('确定否决审核吗？')");
    }
    protected void gbshowreducecontinue_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
        Label longid = (Label)row.FindControl("lbllongid");
        if (longid != null)
        {
            if (e.CommandName == "pass")
            {
                reduce.SetReduceContinuePass(longid.Text, Convert.ToInt32(e.CommandArgument.ToString()));
                PageBind();
            }
            if (e.CommandName == "unpass")
            {
                reduce.SetReduceContinueUnPass(Convert.ToInt32(e.CommandArgument.ToString()));
                PageBind();
            }
        }
    }
    protected void gbshowsubsidycontinue_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
        Label longid = (Label)row.FindControl("lbllongid");
        if (longid != null)
        {
            if (e.CommandName == "pass")
            {
                subsidy.SetSubsidyContinuePass(longid.Text, Convert.ToInt32(e.CommandArgument.ToString()));
                PageBind();
            }
            if (e.CommandName == "unpass")
            {
                subsidy.SetSubsidyContinueUnPass(Convert.ToInt32(e.CommandArgument.ToString()));
                PageBind();
            }
        }
    }
    protected void gbshowsubsidycontinue_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        LinkButton lkbpass = (LinkButton)e.Row.FindControl("lkbtnsubpass");
        if (lkbpass != null)
            lkbpass.Attributes.Add("onclick", "return confirm('确定通过审核吗？')");
        LinkButton lkbunpass = (LinkButton)e.Row.FindControl("lkbtnsubpass");
        if (lkbunpass != null)
            lkbunpass.Attributes.Add("onclick", "return confirm('确定否决审核吗？')");
    }
    protected void gvreissue_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "pass")
        {
            apply.SetApplyReissuePass(e.CommandArgument.ToString());
            PageBind();
        }
        if (e.CommandName == "unpass")
        {
            apply.SetApplyReissueUnpass(e.CommandArgument.ToString());
            PageBind();
        }
    }
    protected void gvreissue_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        LinkButton lkbpass = (LinkButton)e.Row.FindControl("lkbtnreissuepass");
        if (lkbpass != null)
            lkbpass.Attributes.Add("onclick", "return confirm('确定通过审核吗？')");
        LinkButton lkbunpass = (LinkButton)e.Row.FindControl("lkbtbreissueunpass");
        if (lkbunpass != null)
            lkbunpass.Attributes.Add("onclick", "return confirm('确定否决审核吗？')");
    }
    protected void GridView_applyHistory_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void GridView_applyHistory_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.ToLower() == "check")
        {
            ApplyHistory.checkHistory(e.CommandArgument.ToString());
            PageBind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //SqlParameter[] param = new SqlParameter[1];
        //param[0] = new SqlParameter("@yearmonth", Convert.ToInt32(startYear.SelectedValue +  formatMonth(startMonth.SelectedValue)));
        //SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionString, "ImportHistoryDataByApply", param);       
    }
    private string formatMonth(string m)
    {
        if (Convert.ToInt32(m) < 10)
            m = "0" + m;
        return m;
            
    }
}
